﻿using MslDiary.Framework;
using MslDiary.Model;
// 版权所有：2015  All Rights Reserved.
// 文 件 名：A_UserBLL.cs
// 功能描述：
// 创建标识：m.sh.lin0328@163.com 2015/1/2 17:17:42
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data.SQLite;
using System.IO;
using System.Text;
using System.Xml;
namespace MslDiary.BLL
{
    public class A_UserBLL : MSL.Tool.Data.DBAccessBase<Model.A_User>
    {
        #region 构造

        public A_UserBLL()
            : base("A_User", "Id", true)
        {

        }
        #endregion

        /// <summary>
        /// 保存登录用户信息
        /// </summary>
        /// <param name="account"></param>
        /// <param name="pwd"></param>
        /// <param name="isSavePwd"></param>
        public void SaveLoginUserConfig(string account, string pwd, bool isSavePwd)
        {
            string path = Gloable.StartPath + "\\data\\user.xml";
            MslDiary.Framework.IO.ConfigHelper userConfig = new MslDiary.Framework.IO.ConfigHelper(path);
            string aPath = "User/Name[@account='" + account + "']";
            string encryptPwd = isSavePwd ? MslDiary.Framework.Helper.EncryptDbPwd(account, pwd) : "";
            if (!userConfig.NodeIsExists(aPath))
            {
                userConfig.AppendNode("/Configuration/User", "Name", "account", account);
                userConfig.AddAttribute(aPath, "pwd", encryptPwd);
            }
            else
            {
                userConfig.SetAttribute(aPath, "pwd", encryptPwd);
            }

            XmlNodeList nodeList = userConfig.SelectSelectNodes("/Configuration/User/Name");
            if (nodeList != null && nodeList.Count > 0)
            {
                string nodeName = String.Empty;
                string nodeDb = String.Empty;
                string nodeConfig = String.Empty;// MFW.Gloable.StartPath + "\\data\\" + nodeName + "_config.xml";
                foreach (XmlNode node in nodeList)
                {
                    nodeName = node.Attributes["account"].Value;
                    nodeConfig = Gloable.StartPath + "\\data\\" + nodeName + "_config.xml";
                    nodeDb = Gloable.StartPath + "\\data\\" + nodeName + "_db.db";
                    if (!File.Exists(nodeConfig) && !File.Exists(nodeDb))
                    {
                        userConfig.RemoveNodeValueByPath("/Configuration/User", "/Configuration/User/Name[@account='" + nodeName + "']");
                    }
                }
            }
            userConfig.Save();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="conn">配置文件中的链接字符串</param>
        /// <param name="account"></param>
        /// <param name="pwd"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool Login(string conn, string account, string pwd, out string msg)
        {
            msg = "加载数据库配置...";
            MSL.Tool.Data.DbHelper.ConnectionString = String.Format(conn + "Password=" + pwd, Gloable.StartPath + @"\data\", account);

            if (!MSL.Tool.Data.DbHelper.Instance.IsLoginSuccess())
            {
                msg = "登录失败，数据库密码不正确！";
                return false;
            }
            //备份数据库 .bak
            string dbPath = Gloable.StartPath + @"\data\" + account + "_db.db";
            string bakDbPath = dbPath.Replace(".db", ".bak");
            if (File.Exists(bakDbPath)) MSL.Tool.IOHelper.Instance.DeleteFile(bakDbPath);
            MSL.Tool.Data.DbHelper.Instance.Reset();//收缩数据库
            MSL.Tool.IOHelper.Instance.CopyFile(dbPath, bakDbPath);

            Gloable.DiaryLoginPwd = pwd;
            msg = "登录成功！";
            try
            {
                MslDiary.Model.A_User mod = null;
                A_UserBLL userBLL = new A_UserBLL();
                mod = userBLL.GetModelByAccount(account);
                if (mod == null || mod.Account == null)
                {
                    msg = "用户信息获取失败！";
                    return false;
                }
                ReadUserInfo(mod);
            }
            catch (Exception)
            {
                msg = "用户信息获取失败！";
                return false;
            }
            return true;
        }

        public void ReadUserInfo(MslDiary.Model.A_User mod)
        {
            if (mod == null || mod.Account == null)
            {
                return;
            }
            Gloable.Name = mod.Name;
            Gloable.CurrentLoginedAccount = mod.Account;
            Gloable.NickName = mod.NickName;
            Gloable.NoteIsLock = false;
            Gloable.DiaryIsLock = false;
            //Gloable.IsImmediatelyLock = false;

            if (mod.NoteIsLock != null && mod.NoteIsLock.Equals("1") && !String.IsNullOrEmpty(mod.NoteLockPwd))
            {
                Gloable.NoteLockPwd = mod.NoteLockPwd;
                Gloable.DiaryLockPwd = MSL.Tool.Security.DESEncrypt.Instance.Decrypt(mod.NoteLockPwd, Framework.Gloable.NormalEncryptKey);
            }
            if (mod.DiaryIsLock != null && mod.DiaryIsLock.Equals("1") && !String.IsNullOrEmpty(mod.DiaryLockPwd))
            {
                Gloable.DiaryIsLock = true;
                Gloable.DiaryLockPwd = MSL.Tool.Security.DESEncrypt.Instance.Decrypt(mod.DiaryLockPwd, Framework.Gloable.NormalEncryptKey);
                Gloable.LeaveTimeToLock = mod.LeaveTimeToLock;
            }
        }
        public A_User GetModelByAccount(string account)
        {
            if (String.IsNullOrEmpty(account))
                return null;

            return base.GetEntity(String.Format(" Account='{0}' AND IsDelete='0' ", account));
        }
        /// <summary>
        /// 新建日记本
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool AddDiary(string account, string nickName, string dbLoginPwd, out string msg)
        {
            bool isOK = true;
            msg = String.Empty;
            if (String.IsNullOrEmpty(account) || String.IsNullOrEmpty(dbLoginPwd))
            {
                msg = "登录名或密码不能为空！";
                return false;
            }
            //生成数据库 
            string dbname = account + "_db.db";
            string dbPath = Gloable.StartPath + "\\data\\" + dbname;
            string xmlPath = Gloable.StartPath + "\\data\\" + account + "_config.xml";
            if (File.Exists(dbPath) && File.Exists(xmlPath))
            {
                msg = "此登录名已经存在，请重新填写！";
                return false;
            }
            if (!CreateUserDataBase(dbPath, dbname, account, nickName, dbLoginPwd, out msg))
            {
                MSL.Tool.IOHelper.Instance.DeleteFile(dbPath);
                return false;
            }
            //生成配置文件
            if (!CreateUserConfig(account, out msg))
            {
                MSL.Tool.IOHelper.Instance.DeleteFile(dbPath);
                return false;
            }
            //保存加密后的密码到文件
            SaveEncryptPwdToFile(account, dbLoginPwd);

            return isOK;
        }
        /// <summary>
        /// 保存加密后的密码到文件
        /// </summary>
        /// <param name="account"></param>
        /// <param name="dbLoginPwd"></param>
        public void SaveEncryptPwdToFile(string account, string dbLoginPwd)
        {
            if (String.IsNullOrEmpty(account) || String.IsNullOrEmpty(dbLoginPwd))
                return;

            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog
            {
                Filter = "密钥文件用于找回密码，请妥善保存(*.lic)|*.lic",
                RestoreDirectory = true
            };
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                MSL.Tool.IOHelper.Instance.WriteFile(sfd.FileName, MslDiary.Framework.Helper.EncryptDbPwd(account, dbLoginPwd));
            }
        }
        #region 生成数据库与表结构
        /// <summary>
        /// 生成数据库与表结构 所有参数不为空
        /// </summary>
        /// <param name="dbPath"></param>
        /// <param name="dbname"></param>
        /// <param name="account"></param>
        /// <param name="nickName"></param>
        /// <param name="dbLoginPwd"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool CreateUserDataBase(string dbPath, string dbname, string account, string nickName, string dbLoginPwd, out string msg)
        {
            msg = String.Empty;
            try
            {
                SQLiteConnection.CreateFile(dbPath);
                //生成表结构与基础数据
                string dbScript = MSL.Tool.IOHelper.ReadFile(Gloable.StartPath + "\\data\\Import_Tables.sql").Replace("\"", "");
                string conn = String.Format(@"Data Source={0}\data\{1};failifmissing=false;Pooling=True;", Gloable.StartPath, dbname);
                int num = MSL.Tool.Data.DbHelper.Instance.ExecSql(conn, dbScript, new System.Collections.Hashtable());
                //设置数据库密码
                MSL.Tool.Data.DbHelper.ConnectionString = conn;
                MSL.Tool.Data.DbHelper.Instance.ChangePassword(dbLoginPwd);
                //A_User 添加记录
                string sql = String.Format(
    @"
INSERT INTO A_User(Account,NickName,DiaryIsLock,NoteIsLock,LeaveTimeToLock,IsDelete)
VALUES('{0}','{1}','0','0',0,'0')
", account, nickName);
                num = MSL.Tool.Data.DbHelper.Instance.ExecSql(conn, sql, new System.Collections.Hashtable());
                if (num <= 0)
                {
                    msg = "用户信息保存失败！";
                    MSL.Tool.IOHelper.Instance.DeleteFile(dbPath);
                    return false;
                }
                //A_Item 添加记录
                if (!AddItem(account, dbPath, conn, out msg))
                {
                    MSL.Tool.IOHelper.Instance.DeleteFile(dbPath);
                    string xmlPath = Gloable.StartPath + "\\data\\" + account + "_config.xml";
                    MSL.Tool.IOHelper.Instance.DeleteFile(xmlPath);
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                msg = "用户信息保存失败！";
                MSL.Tool.LogHelper.Instance.WriteLog(ex.ToString());
                return false;
            }
        }
        #endregion

        #region 添加字典表数据
        /// <summary>
        /// 添加字典项数据 所有参数不为空
        /// </summary>
        /// <param name="account"></param>
        /// <param name="dbPath"></param>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool AddItem(string account, string dbPath, string conn, out string msg)
        {
            msg = String.Empty;
            string sql =
@"
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(1,0,'记事本类型','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(3,1,'工作','gongzuo','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(4,1,'生活','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(5,1,'私人','siren','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(7,1,'家庭','Family','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(8,1,'公司','431234','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(9,1,'朋友','Friend','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(10,1,'临时','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(11,1,'其他','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(12,0,'天气类型','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(13,12,'晴','','\res\weather\weather_sun.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(14,12,'晴转多云','qing','\res\weather\weather_cloudy.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(15,12,'晴转多云加小雨','','\res\weather\weather_cloudy_rain.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(16,12,'雷电','','\res\weather\weather_lightning.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(17,12,'阴','','\res\weather\weather_cloud.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(18,12,'多云','','\res\weather\weather_clouds.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(19,12,'雨','','\res\weather\weather_rain.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(20,12,'雪','','\res\weather\weather_snow.png',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(21,0,'日记类别（标签 ）','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(22,0,'日记分组','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(24,0,'日记心情','mood','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(25,1,'家庭','Family','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(39,24,'高兴','','\res\mood\0.gif',1,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(40,24,'难过','','\res\mood\5.gif',4,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(41,24,'疑问','','\res\mood\3.gif',2,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(42,24,'狂怒','','\res\mood\1.gif',6,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(43,24,'疑问','','\res\mood\3.gif',2,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(45,24,'爱','','\res\mood\6.gif',7,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','0');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(48,22,'重要','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(49,1,'情感','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(50,21,'生活杂记','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(51,21,'心情随笔','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(52,21,'工作笔记','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(53,24,'委屈','','\res\mood\4.gif',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
INSERT INTO A_Item(Id,FatherId,Name,EnName,Path,Sort,IsDelete,IsEnable,CreateDate,ModifyDate,IsAllowDelete)VALUES(55,22,'杂乱','','',0,'0','1','2015/5/26 13:02:36','2015/5/26 13:02:36','1');
";
            int num = MSL.Tool.Data.DbHelper.Instance.ExecSql(conn, sql, new System.Collections.Hashtable());
            if (num <= 0)
            {
                msg = "插入字典项数据出错！";
                return false;
            }
            #region 添加一条欢迎日记

            try
            {
                string content = "<FlowDocument LineHeight='5' PagePadding='5,0,5,0' AllowDrop='True' NumberSubstitution.CultureSource='User' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><Paragraph Margin='0,0,0,0' FontFamily='宋体' FontSize='12'><Run xml:lang='zh-cn'>欢迎使用本日记本程序，有什么意见欢迎E-Mail：m.sh.lin0328@163.com给我或者给我QQ留言：515153841。</Run></Paragraph><Paragraph TextIndent='20' Margin='0,0,0,0' FontFamily='宋体' FontSize='12'><Run xml:lang='zh-cn'>祝您使用的开心！</Run></Paragraph><Paragraph TextIndent='20' Margin='0,0,0,0' FontFamily='宋体' FontSize='12'><Run xml:lang='zh-cn' xml:space='preserve' /></Paragraph><Paragraph TextIndent='20' Margin='0,0,0,0' FontFamily='宋体' FontSize='12'><Run xml:lang='zh-cn'>2015年5月31日</Run></Paragraph></FlowDocument>";

                A_DiaryBLL diaryBLL = new A_DiaryBLL();
                A_Diary diaryMod = new A_Diary();
                diaryMod.Title = "欢迎使用本日记软件";
                diaryMod.WeatherId = 13;
                diaryMod.MoodId = 41;
                diaryMod.IsDelete = "0";
                diaryMod.IsEnable = "1";
                diaryMod.Summary = "欢迎使用本日记本程序，有什么意见欢迎E-Mail:m.sh.lin0328@163.com";
                diaryMod.Content = content;
                diaryMod.DiaryDate = DateTime.Now;
                diaryMod.CreateDate = DateTime.Now;
                diaryMod.ModifyDate = DateTime.Now;
                diaryMod.DiaryYear = DateTime.Now.Year;
                diaryMod.DiaryMonth = DateTime.Now.Month;
                diaryMod.DiaryDay = DateTime.Now.Day;
                diaryMod.BackGroundPath = "default.jpg";
                diaryBLL.Add(diaryMod);
            }
            catch (Exception ex)
            {
                MSL.Tool.LogHelper.Instance.WriteLog(ex.ToString());
            }
            #endregion
            return true;
        }
        #endregion

        #region 创建用户配置文件

        /// <summary>
        /// 创建用户配置文件 所有参数不为空
        /// </summary>
        /// <param name="account">登录帐号</param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private bool CreateUserConfig(string account, out string msg)
        {
            msg = String.Empty;
            //生成配置文件
            string xml =
@"<?xml version='1.0' encoding='utf-8'?>
<Configuration>
  <AppBackgroundImage title='程序背景图'></AppBackgroundImage>
  <EditorBackgroundImage title='编辑框背景图'></EditorBackgroundImage>
  <MinimizeToTray title='最小化到系统托盘'>1</MinimizeToTray>
  <SaveLog title='是否记录运行日志'>1</SaveLog>
  <AutoCheckUpdate title='自动检查更新'>1</AutoCheckUpdate>
  <MinimizeToAutoLock title='窗口最小化或关闭时锁定'>0</MinimizeToAutoLock>
  <IsAutoRun title='是否开机启动'>0</IsAutoRun>
  <ThemeAccent title='主题名称'></ThemeAccent>
  <Conn>Data Source={0}\{1}_db.db;failifmissing=false;Pooling=True;</Conn>
</Configuration>
";
            string xmlPath = Gloable.StartPath + "\\data\\" + account + "_config.xml";
            MSL.Tool.IOHelper.Instance.WriteFile(xmlPath, xml.Replace("'", "\""));
            if (!File.Exists(xmlPath))
            {
                msg = "用户配置信息保存失败！";
                return false;
            }
            return true;
        }
        #endregion
    }
}
